﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<div class="modal-dialog x-modal-dialog" style="width:800px;">

  <div class="modal-content">

    <div class="modal-header x-breadcrumb clearfix">

      <h2><i class="glyphicon glyphicon-fire" title="编辑批次"></i>&nbsp;&nbsp;<span>编辑批次</span></h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <form class="form-horizontal" method="POST" action="${ctx.host}/coupon-batches/${couponBatch.id}" data-validate="true">
      
      <input type="hidden" name="_method" value="PATCH">
      <input type="hidden" name="batchId" value="${couponBatch.id }">
      
      <div class="modal-body">
        <div class="form-group x-form-group">
          <label class="col-xs-2 control-label">优惠券模版</label>
          <div class="pull-left" style="width: 30%">
            <p class="form-control-static">${couponBatch.templateName}</p>
          </div>
          
          <label class="col-xs-2 control-label">批次名称</label>
          <div class="pull-left" style="width: 30%">
            <input type="text" class="form-control" name="name" value="${couponBatch.name}"/>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-2 control-label">本次发放总数</label>
          <div class="pull-left" style="width: 30%">
            <input type="text" class="form-control" name="amount" data-validate="required|number" value="${couponBatch.amount}" />
          </div>
          
          <label class="col-xs-2 control-label">截止日类型</label>
          <div class="pull-left" style="width: 30%">
            <select name="inputExpireType" class="form-control select2" data-validate="required">
              <option value=""></option>
              <c:forEach var="expireType" items="${enums['expireType']}" >
                <option value="${expireType}" ${expireType == couponBatch.expireType ? 'selected':''}>${expireType.description}</option>
              </c:forEach>
            </select>
          </div>
        </div>
        
        <div id="effectiveDays" class="form-group x-form-group">
          <label class="col-xs-2 control-label">固定天数</label>
          <div class="pull-left" style="width: 30%">
            <input type="text" class="form-control" name="effectiveDays" placeholder="请输入固定天数" value="${couponBatch.effectiveDays}"/>
          </div>
        </div>
        
        <div id="effectiveStartDate" class="form-group x-form-group hide">
          <label class="col-xs-2 control-label">开始日期</label>
          <div class="pull-left" style="width: 30%">
            <div class="input-group date">
              <input type="text" name="effectiveStartDate" class="form-control" value="${couponBatch.effectiveStartDate}"/>
              <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
            </div>
          </div>
        </div>
        
        <div id="effectivEndDate" class="form-group x-form-group hide">
          <label class="col-xs-2 control-label">截止日期</label>
          <div class="pull-left" style="width: 30%">
            <div class="input-group date">
              <input type="text" name="effectiveEndDate" class="form-control" value="${couponBatch.effectiveEndDate}"/>
              <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
            </div>
          </div>
        </div>
        
      </div>

      <div class="modal-footer clearfix">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div>
    </form>

  </div>

</div>

<script src="${ctx.resource}/js/bootstrap.validate.trigger.js"></script>
<script>

  $(function() {
    $('.date').datetimepicker({
      format: 'yyyy-mm-dd',
      autoclose: true,
      language: 'zh-CN',
      todayBtn: 'linked',
      todayHighlight: true,
      pickerPosition: 'bottom-right',
      minView: 'month'
    });
    
    $('select[name="inputExpireType"]').select2({
      placeholder : '请选择截止日期类型',
      minimumResultsForSearch : -1,
      allowClear : true
    });
    
    $('select[name="couponTemplate"]').select2({
      placeholder : '请选择所属模版',
      minimumResultsForSearch : 5,
      allowClear : true
    });
    
  })
</script>
